package com.itheima.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.itheima.entity.PageResult;
import com.itheima.entity.StatusCode;
import com.itheima.pojo.ExceptionLog;
import com.itheima.pojo.SysLog;
import com.itheima.service.ExceptionLogService;
import com.itheima.utils.ResultUtil;
import com.itheima.service.SysLogService;
import com.itheima.vo.ExceptionLogVO;
import com.itheima.vo.SysLogVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/log")
@Api(tags = "操作日志相关接口")
@CrossOrigin
public class LogRestController {

    @Autowired
    private SysLogService sysLogService;

    @Autowired
    private ExceptionLogService exceptionLogService;
    /*
    * 分页查询
    * 获取用户日志列表
    * */
    @ApiOperation("获取用户日志列表") @PostMapping("/getLogList")
    public String getLogList(@RequestBody(required = false) SysLogVO sysLogVO) {
        Page<SysLog> logList = sysLogService.findLogListPage(sysLogVO);
        Map<String, Object> map = new HashMap();
        map.put("records",logList.getResult());
        map.put("total",logList.getTotal());
        map.put("size",logList.getPageSize());
        map.put("current",logList.getPageNum());
        map.put("orders","");
        map.put("optimizeCountSql",true);
        map.put("isSearchCount",true);
        return ResultUtil.result("success", map);
    }
    @ResponseBody

    /*
     * 分页查询
     * 获取异常日志列表
     * */
    @ApiOperation("获取系统异常列表")
    @PostMapping("/getExceptionList")
    public String getException(@RequestBody(required = false) ExceptionLogVO exceptionLogVO){
        Page<ExceptionLog> logList = exceptionLogService.findLogListPage(exceptionLogVO);
        Map<String, Object> map = new HashMap();
        map.put("records",logList.getResult());
        map.put("total",logList.getTotal());
        map.put("size",logList.getPageSize());
        map.put("current",logList.getPageNum());
        map.put("orders","");
        map.put("optimizeCountSql",true);
        map.put("isSearchCount",true);
        return ResultUtil.result("success", map);
    }
}
